using System;
using System.Windows.Forms;
using Jonathan.Tabber;

namespace Jonathan.Controls
{
	/// <summary>
	/// Control used to create and save notes inside of Jonathan.
	/// </summary>
    public class CtrlNote : TabberPage
    {
        private readonly ctrlTextNote m_Note;

		/// <summary>
		/// Creates a new Note Control.
		/// </summary>
        public CtrlNote ()
        {
			this.m_Note = new ctrlTextNote { Dock = DockStyle.Fill };
		   this.Controls.Add(this.m_Note);
			this.TabTitle = "New Note";
			this.Load += CtrlNoteLoad;
        }

		void CtrlNoteLoad (object sender, EventArgs e)
		{
         this.m_Note.SetNoteTab (this);
         this.Anchor = AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right | AnchorStyles.Top;
		}

        /// <summary>
        /// Opens the given file...
        /// </summary>
        /// <param name="filePath">Path of File to Open.</param>
        public void OpenFile (string filePath)
        {
            this.m_Note.OpenFile(filePath);
        }

		/// <summary>
		/// Override to get the tab page's info on closing.
		/// </summary>
		/// <returns>String of Info to be saved.</returns>
        public override string GetPageInfo ()
		{
		   if (string.IsNullOrEmpty(this.m_Note.File))
            return base.GetPageInfo();
		   return this.m_Note.File;
		}
    }
}
